#!/bin/zsh

PACKAGE_PATH="cn/com/wanwei/zion/explain/seckill"
BASE_DIR="src/main/java/${PACKAGE_PATH}"

mkdir -p ${BASE_DIR}/{entity,mapper,service,controller}

# Entity
cat > ${BASE_DIR}/entity/SeckillResultEntity.java <<EOF
package cn.com.wanwei.zion.explain.seckill.entity;

import cn.com.wanwei.zion.explain.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName("seckill_result")
@ApiModel(value = "秒杀结果实体", description = "秒杀结果表")
public class SeckillResultEntity extends BaseEntity {
    @ApiModelProperty(value = "用户ID", required = true)
    private Long userId;

    @ApiModelProperty(value = "活动ID", required = true)
    private Long activityId;

    @ApiModelProperty(value = "商品ID", required = true)
    private Long itemId;

    @ApiModelProperty(value = "秒杀商品ID", required = true)
    private Long seckillItemId;

    @ApiModelProperty(value = "结果：0-失败，1-成功", required = true)
    private Integer result;

    @ApiModelProperty(value = "原因")
    private String reason;
}
EOF

# Mapper
cat > ${BASE_DIR}/mapper/SeckillResultMapper.java <<EOF
package cn.com.wanwei.zion.explain.seckill.mapper;

import cn.com.wanwei.zion.explain.seckill.entity.SeckillResultEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SeckillResultMapper extends BaseMapper<SeckillResultEntity> {
}
EOF

# Service Interface
cat > ${BASE_DIR}/service/SeckillResultService.java <<EOF
package cn.com.wanwei.zion.explain.seckill.service;

import cn.com.wanwei.zion.explain.seckill.entity.SeckillResultEntity;
import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.extension.service.IService;

public interface SeckillResultService extends IService<SeckillResultEntity> {
    PageResponse<SeckillResultEntity> pageList(Integer pageIndex, Integer pageSize);
}
EOF

# Service Implementation
cat > ${BASE_DIR}/service/impl/SeckillResultServiceImpl.java <<EOF
package cn.com.wanwei.zion.explain.seckill.service.impl;

import cn.com.wanwei.zion.explain.seckill.entity.SeckillResultEntity;
import cn.com.wanwei.zion.explain.seckill.mapper.SeckillResultMapper;
import cn.com.wanwei.zion.explain.seckill.service.SeckillResultService;
import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class SeckillResultServiceImpl extends ServiceImpl<SeckillResultMapper, SeckillResultEntity> implements SeckillResultService {
    @Override
    public PageResponse<SeckillResultEntity> pageList(Integer pageIndex, Integer pageSize) {
        Page<SeckillResultEntity> page = new Page<>(pageIndex, pageSize);
        page(page);
        return PageResponse.of(page.getRecords(), (int) page.getTotal(), pageSize, pageIndex);
    }
}
EOF

# Controller
cat > ${BASE_DIR}/controller/SeckillResultController.java <<EOF
package cn.com.wanwei.zion.explain.seckill.controller;

import cn.com.wanwei.zion.explain.seckill.entity.SeckillResultEntity;
import cn.com.wanwei.zion.explain.seckill.service.SeckillResultService;
import com.alibaba.cola.dto.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@Api(tags = "秒杀结果管理模块")
@RestController
@RequestMapping("/seckillResult")
public class SeckillResultController {
    private final String MODULE_NAME = "秒杀结果管理";
    
    @Resource
    private SeckillResultService seckillResultService;

    @ApiOperation("分页查询秒杀结果")
    @PostMapping("/page")
    public PageResponse<SeckillResultEntity> pageList(
            @RequestParam Integer pageIndex,
            @RequestParam Integer pageSize) {
        return seckillResultService.pageList(pageIndex, pageSize);
    }
}
EOF

echo "代码生成完成"
